<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>发布岗位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8">
    <link rel="stylesheet" href="/Sys/css/layui.css">
    <link rel="stylesheet" href="/Sys/css/sign.css">
    <link rel="stylesheet" href="/Sys/js/css/modules/layui-icon-extend/iconfont.css">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/Sys/css/font.css">
    <link rel="stylesheet" href="/Sys/css/xadmin.css">
    <script type="text/javascript" src="/Sys/js/jquery-3.3.1.min.js"></script>
    <script src="/Sys/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="departmentName" class="layui-form-label">
                <span class="x-red">*</span>科室名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="departmentName" name="departmentName" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="location" class="layui-form-label">
                <span class="x-red">*</span>科室地点
            </label>
            <div class="layui-input-inline">
                <input type="text" id="location" name="location" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="jobType" class="layui-form-label">
                <span class="x-red">*</span>工作性质
            </label>
            <div class="layui-input-inline">
                <select id="jobType" name="jobType" required lay-verify="required">
                    <option value="">请选择工作性质</option>
                    <option value="固定岗">固定岗</option>
                    <option value="临时岗">临时岗</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="supervisor" class="layui-form-label">
                <span class="x-red">*</span>负责人
            </label>
            <div class="layui-input-inline">
                <input type="text" id="supervisor" name="supervisor" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="contactPhone" class="layui-form-label">
                <span class="x-red">*</span>联系电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="contactPhone" name="contactPhone" required lay-verify="required|phone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="workingHours" class="layui-form-label">
                <span class="x-red">*</span>工作时间（工作日）
            </label>
            <div class="layui-input-inline">
                <select name="workingHours" id="workingHours" lay-verify="required">
                    <option value="">请选择时间段</option>
                    <option value="08:00-10:00">08:00-10:00</option>
                    <option value="10:00-12:00">10:00-12:00</option>
                    <option value="14:00-16:00">14:00-16:00</option>
                    <option value="16:00-18:00">16:00-18:00</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="salary" class="layui-form-label">
                <span class="x-red">*</span>薪酬
            </label>
            <div class="layui-input-inline">
                <input type="text" id="salary" name="salary" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="headcount" class="layui-form-label">
                <span class="x-red">*</span>所需人数
            </label>
            <div class="layui-input-inline">
                <input type="number" id="headcount" name="headcount" required lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                发布
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            // 添加当前用户作为创建者
            data.field.createdBy = '[[${session.account}]]';
            data.field.status = '待审批';
            
            //发异步，把数据提交给后端
            $.ajax({
                url: '/Sys/job/add',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function(res){
                    if(res.code === 0){
                        layer.msg('添加成功', {
                            icon: 1,
                            time: 2000
                        }, function(){
                            // 关闭当前frame
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            // 刷新父页面
                            parent.location.reload();
                        });
                    } else {
                        layer.msg('发布失败：' + (res.msg || '未知错误'), {icon: 2});
                    }
                },

            });
            return false;
        });
    });
</script>
</body>
</html> 